<?php
function b($a,$b="",$c=0,$d="")
{
	global $arr;
	if(trim($a)=="")
	{
		$arr[] = $b;
		return;
	}
	if($c>0)
	{
		if(strlen($a)<$c)
		{
			$arr[] = $d;
			return;
		}
	}
}
function i($a,$b="",$c=0,$d="")
{
	global $arr;
	if($a=="")
		return;
	if(!(is_numeric($a)))
	{
		$arr[] = $b;
		return;
	}
	if($c>0)
	{
		if(strlen($a)<$c)
		{
			$arr[] = $d;
			return;
		}
	}
}
function e($a,$b="",$c=0,$d="")
{
	global $arr;
	if(trim($a)=="")
	{
		$arr[] = $b;
		return;
	}
	if (eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) 
	{
		$arr[] = $d;
		return;
	}
}

function pc($a,$b="",$c,$d="")
{
	global $arr;
	if($a!=$c)
	{
		$arr[] = $b;
		return;
	}
}
function se()
{
	global $arr, $msg;
	if(count($arr)>0)
	{
		echo "<table id='error' align='center'>
				<tr>
					<td>&nbsp;&nbsp;Error(s) while processing your request</td>
				</tr>
				<tr><td><ol>";
			echo "<li>".implode("</li><li>",$arr)."</li>";
				
		echo "</ol></td></tr></table>";
	}
	elseif($msg!="")
	{
		echo "<br><br><table id='error' align='center'>
				<tr>
					<td>$msg</td>
				</tr></table>";
	}
}
function gettable($table,$col="*",$where,$orderby,$sort,$page,$action,$hiddencol,$reparr,$reptype=null)
{
	global $con, $pagelength;
	// How many adjacent pages should be shown on each side?
	$adjacents = 3;

	// First get total number of rows in data table. 
	$sql = "SELECT count(*) as num FROM $table $where" ;
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
	$total_pages = $row['num'];

	/* Setup vars for query. */
	$targetpage = $_SERVER['PHP_SELF'].'?'; 	//your file name  (the name of this file)

	$limit = $pagelength;	//how many items to show per page
	if(!$limit) 
		$limit = 50;
		
	$page = $_GET['page'];
	if($page) 
		$start = ($page - 1) * $limit;	//first item to display on this page
	else
		$start = 0;	//if no page var is given, set start to 0

	/* Setup page vars for display. */
	if ($page == 0) $page = 1;					//if no page var is given, default to 1.
	$prev = $page - 1;							//previous page is page - 1
	$next = $page + 1;							//next page is page + 1
	$lastpage = ceil($total_pages/$limit);		//lastpage is = total pages / items per page, rounded up.
	$lpm1 = $lastpage - 1;						//last page minus 1
	
	/* 
		Now we apply our rules and draw the pagination object. 
		We're actually saving the code to a variable in case we want to draw it more than once.
	*/
	$pagination = "";
	if($lastpage > 1)
	{	
		$pagination .= "<div class=\"pagination\">";
		//previous button
		if ($page > 1) 
			$pagination.= "<a href=\"$targetpage&page=$prev\">&laquo; previous</a>";
		else
			$pagination.= "<span class=\"disabled\">&laquo; previous</span>";	
		
		//pages	
		if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";					
			}
		}
		elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some
		{
			//close to beginning; only hide later pages
			if($page < 1 + ($adjacents * 2))		
			{
				for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
				{
					if ($counter == $page)
						$pagination.= "<span class=\"current\">$counter</span>";
					else
						$pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";					
				}
				$pagination.= "...";
				$pagination.= "<a href=\"$targetpage&page=$lpm1\">$lpm1</a>";
				$pagination.= "<a href=\"$targetpage&page=$lastpage\">$lastpage</a>";		
			}
			//in middle; hide some front and some back
			elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
			{
				$pagination.= "<a href=\"$targetpage&page=1\">1</a>";
				$pagination.= "<a href=\"$targetpage&page=2\">2</a>";
				$pagination.= "...";
				for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
				{
					if ($counter == $page)
						$pagination.= "<span class=\"current\">$counter</span>";
					else
						$pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";					
				}
				$pagination.= "...";
				$pagination.= "<a href=\"$targetpage&page=$lpm1\">$lpm1</a>";
				$pagination.= "<a href=\"$targetpage&page=$lastpage\">$lastpage</a>";		
			}
			//close to end; only hide early pages
			else
			{
				$pagination.= "<a href=\"$targetpage&page=1\">1</a>";
				$pagination.= "<a href=\"$targetpage&page=2\">2</a>";
				$pagination.= "...";
				for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page)
						$pagination.= "<span class=\"current\">$counter</span>";
					else
						$pagination.= "<a href=\"$targetpage&page=$counter\">$counter</a>";					
				}
			}
		}
		
		//next button
		if ($page < $counter - 1) 
			$pagination.= "<a href=\"$targetpage&page=$next\">next &raquo;</a>";
		else
			$pagination.= "<span class=\"disabled\">next &raquo;</span>";
		$pagination.= "</div>\n";		
	}
	
			
	/* Get data. */
	$orderby = ($orderby != '') ? 'order by '.$orderby : '';
	$sql = "select $col from $table $where $orderby $sort limit $start,$limit";
	$result = mysql_query($sql);

	$i = 0;
	echo $pagination;
	echo "<table width=100% border=0 id='report'>";
	echo "<tr id='headrep'><th>#</th>";
	$colarr=Array();
	while ($i < mysql_num_fields($result)) 
	{
	    $meta = mysql_fetch_field($result, $i);
	    if ($meta)
	    {
	    	$colarr[$meta->name] = $meta->name;
	    	if(in_array($meta->name,$hiddencol)==false)
	    	{
	    		$sort=trim($sort);
	    		$ord = trim(str_replace("order by","",$orderby));
	    		$ord = trim(str_replace("`","",$orderby));
			echo "<th>".(ucwords(str_replace("_"," ",$meta->name)));
			if($meta->name==$ord && $sort=="asc")
			{
				echo " <a href='?pg=$pg&orderby=`".$meta->name."`&sort=desc' style='text-decoration:none'>";
				echo "&#9660;";
				echo "</a>";
			}
			elseif($meta->name==$ord && $sort=="desc")
			{
				echo " <a href='?pg=$pg&orderby=`".$meta->name."`&sort=asc' style='text-decoration:none'>";
				echo "&#9650;";
				echo "</a>";
			}
			else
			{
				echo " <a href='?pg=$pg&orderby=`".$meta->name."`&sort=asc' style='text-decoration:none'>";
				echo "&#9650;";
				echo "</a>";
				echo " <a href='?pg=$pg&orderby=`".$meta->name."`&sort=desc' style='text-decoration:none'>";
				echo "&#9660;";
				echo "</a>";
			}
			echo "</th>";
		}	    	
	    }
		$i++;
	}
	if($action!="")
		echo "<th>Action</th>";
	echo "</tr>";
	$nm=($start+1);
	$tb_fr_rep="frrep";
	while($row=mysql_fetch_array($result))
	{
		$tb_fr_rep = $tb_fr_rep!="frrep"?"frrep":"secrep";
		echo "<tr id='$tb_fr_rep'><td  align=center>$nm. </td>";
		$n=$action;
		foreach($colarr as $k => $v)
		{
			${$k}=$row[$k];
			if(in_array($k,$hiddencol)==false)
			{
				echo "<td align=center>";
				if(isset($reptype[$k]) && isset($reparr) && isset($reparr[$k]))
				{
					$exps_1 = explode($reptype[$k], (${$k}));
					$sn_1 = Array();
					foreach($exps_1 as $r => $s)
					{
						$sn_1[] = $reparr[$k][$s];
					}
					echo implode($reptype[$k],$sn_1);
				}
				elseif(isset($reparr) && isset($reparr[$k]))
					echo $reparr[$k][(${$k})];
				else
					echo (${$k});
				echo "</td>";
			}
			$n=str_replace("\$$k",(${$k}),$n);
		}
		echo "<td align=center>$n</td>";
		echo "</tr>";
		$nm++;
	}
	echo "</table>";
	echo $pagination;
	
}
function sopt($arr, $selval="")
{
	foreach($arr as $key => $val)
	{
		if(is_array($val))
		{
			echo "<optgroup label='".$key."'>";
				foreach($val as $k => $v){
					$st = ($k == $selval) ? " selected " : "";
					echo "<option value=\"$k\" $st>$v</option>";
				}
			echo "</optgroup>";
		
		} 
		else 
		{	
			$st = ($key == $selval) ? " selected " : "";
			echo "<option value=\"$key\" $st>$val</option>";
		}

	}


}

function amount_word($str)
{
		$word_arr=array();
		$word_arr[0]="Zero";
		$word_arr[1]="One";
		$word_arr[2]="Two";
		$word_arr[3]="Three";
		$word_arr[4]="Four";
		$word_arr[5]="Five";
		$word_arr[6]="Six";
		$word_arr[7]="Seven";
		$word_arr[8]="Eight";
		$word_arr[9]="Nine";
		$word_arr[10]="Ten";
		$word_arr[11]="Eleven";
		$word_arr[12]="Twelve";
		$word_arr[13]="Thirteen";
		$word_arr[14]="Fourteen";
		$word_arr[15]="Fifteen";
		$word_arr[16]="Sixteen";
		$word_arr[17]="Seventeen";
		$word_arr[18]="Eighteen";
		$word_arr[19]="Nineteen";
		$word_arr[20]="Twenty";
		$word_arr[21]="Twenty-one";
		$word_arr[22]="Twenty-two";
		$word_arr[23]="Twenty-three";
		$word_arr[24]="Twenty-four";
		$word_arr[25]="Twenty-five";
		$word_arr[26]="Twenty-six";
		$word_arr[27]="Twenty-seven";
		$word_arr[28]="Twenty-eight";
		$word_arr[29]="Twenty-nine";
		$word_arr[30]="Thirty";
		$word_arr[31]="Thirty-one";
		$word_arr[32]="Thirty-two";
		$word_arr[33]="Thirty-three";
		$word_arr[34]="Thirty-four";
		$word_arr[35]="Thirty-five";
		$word_arr[36]="Thirty-six";
		$word_arr[37]="Thirty-seven";
		$word_arr[38]="Thirty-eight";
		$word_arr[39]="Thirty-nine";
		$word_arr[40]="Forty";
		$word_arr[41]="Forty-one";
		$word_arr[42]="Forty-two";
		$word_arr[43]="Forty-three";
		$word_arr[44]="Forty-four";
		$word_arr[45]="Forty-five";
		$word_arr[46]="Forty-six";
		$word_arr[47]="Forty-seven";
		$word_arr[48]="Forty-eight";
		$word_arr[49]="Forty-nine";
		$word_arr[50]="Fifty";
		$word_arr[51]="Fifty-one";
		$word_arr[52]="Fifty-two";
		$word_arr[53]="Fifty-three";
		$word_arr[54]="Fifty-four";
		$word_arr[55]="Fifty-five";
		$word_arr[56]="Fifty-six";
		$word_arr[57]="Fifty-seven";
		$word_arr[58]="Fifty-eight";
		$word_arr[59]="Fifty-nine";
		$word_arr[60]="Sixty";
		$word_arr[61]="Sixty-one";
		$word_arr[62]="Sixty-two";
		$word_arr[63]="Sixty-three";
		$word_arr[64]="Sixty-four";
		$word_arr[65]="Sixty-five";
		$word_arr[66]="Sixty-six";
		$word_arr[67]="Sixty-seven";
		$word_arr[68]="Sixty-eight";
		$word_arr[69]="Sixty-nine";
		$word_arr[70]="Seventy";
		$word_arr[71]="Seventy-one";
		$word_arr[72]="Seventy-two";
		$word_arr[73]="Seventy-three";
		$word_arr[74]="Seventy-four";
		$word_arr[75]="Seventy-five";
		$word_arr[76]="Seventy-six";
		$word_arr[77]="Seventy-seven";
		$word_arr[78]="Seventy-eight";
		$word_arr[79]="Seventy-nine";
		$word_arr[80]="Eighty";
		$word_arr[81]="Eighty-one";
		$word_arr[82]="Eighty-two";
		$word_arr[83]="Eighty-three";
		$word_arr[84]="Eighty-four";
		$word_arr[85]="Eighty-five";
		$word_arr[86]="Eighty-six";
		$word_arr[87]="Eighty-seven";
		$word_arr[88]="Eighty-eight";
		$word_arr[89]="Eighty-nine";
		$word_arr[90]="Ninety";
		$word_arr[91]="Ninety-one";
		$word_arr[92]="Ninety-two";
		$word_arr[93]="Ninety-three";
		$word_arr[94]="Ninety-four";
		$word_arr[95]="Ninety-five";
		$word_arr[96]="Ninety-six";
		$word_arr[97]="Ninety-seven";
		$word_arr[98]="Ninety-eight";
		$word_arr[99]="Ninety-nine";
		$word_arr[100]="One Hundred";
		
		$word="";
		$str=explode(".",$str);
		$rupees=$str[0];
		$temp1=$str[0];
		$temp2=$str[1];
		if(strlen($temp1)>0){
			for($i=strlen($temp1);strlen($temp1)>0;$i++)
			{
				switch(strlen($temp1))
				{
					case "11":
					{
						$num=abs(substr($temp1,0,2));
						$temp1=substr($temp1,2,strlen($temp1));
						if($num>0)
							$word.=" ".$word_arr[$num]. " Arabs ";
						break;	
					}
					case "10":
					{
						$num=abs(substr($temp1,0,1));
						$temp1=substr($temp1,1,strlen($temp1));
						if($num>0)
							if($num=="1")
								$word.=" ".$word_arr[$num]. " Arab ";
							else
								$word.=" ".$word_arr[$num]. " Arabs ";	
						break;	
					}
					case "9":
					{
						$num=abs(substr($temp1,0,2));
						$temp1=substr($temp1,2,strlen($temp1));
						if($num>0)
							$word.=" ".$word_arr[$num]. " Crores ";
						break;	
					}
					case "8":
					{
						$num=abs(substr($temp1,0,1));
						$temp1=substr($temp1,1,strlen($temp1));
						if($num>0)
							if($num=="1")
								$word.=" ".$word_arr[$num]. " Crore ";
							else
							
								$word.=" ".$word_arr[$num]. " Crores ";
						break;	
					}
					case "7":
					{
						$num=abs(substr($temp1,0,2));
						$temp1=substr($temp1,2,strlen($temp1));
						if($num>0)
							$word.=" ".$word_arr[$num]. " Lakhs ";
						break;	
					}
					case "6":
					{
						$num=abs(substr($temp1,0,1));
						$temp1=substr($temp1,1,strlen($temp1));
						if($num>0)
							if($num=="1")
								$word.=" ".$word_arr[$num]. " Lakh ";
							else
								$word.=" ".$word_arr[$num]. " Lakhs ";
						break;	
					}
					case "5":
					{
						$num=abs(substr($temp1,0,2));
						$temp1=substr($temp1,2,strlen($temp1));
						if($num>0)
							$word.=" ".$word_arr[$num]. " Thousands ";
						break;	
					}
					case "4":
					{
						$num=abs(substr($temp1,0,1));
						$temp1=substr($temp1,1,strlen($temp1));
						if($num>0)
							if($num=="1")
								$word.=" ".$word_arr[$num]. " Thousand ";
							else
								$word.=" ".$word_arr[$num]. " Thousands ";
						break;	
					}
					case "3":
					{
						$num=abs(substr($temp1,0,1));
						$temp1=substr($temp1,1,strlen($temp1));
						if($num>0)
						{
							if($num=="1")
								$word.=" ".$word_arr[$num]. " Hundred ";
							else
								$word.=" ".$word_arr[$num]. " Hundreds ";
						}	
						break;	
					}
					case "2":
					{
						$num=abs(substr($temp1,0,2));
						$temp1=substr($temp1,2,strlen($temp1));
						if($num>0)
							$word.=" ".$word_arr[$num];
						break;	
					}
					case "1":
					{
						$num=abs(substr($temp1,0,2));
						$temp1=substr($temp1,2,strlen($temp1));
						if($num>0)
						{
							if($num=="1")
								$word.=" ".$word_arr[$num];
							else	
								$word.=" ".$word_arr[$num];
						}		
						break;	
					}
				}
			}
		}
		$p="";
		if($temp2!="" && $temp2>0)
		{
			if(strlen($temp2)>2)
			{
				$temp2=substr($temp2,0,2);
			}
			if(strlen($temp2)>1)
			{
				if($temp2<10)
				{
					$p=$word_arr[abs($temp2)]." Paise ";
				}
				else
				{
					$p=$word_arr[$temp2]." Paise ";
				}
			}
			else
			{
				$temp2=$temp2."0";
				$p=$word_arr[$temp2]." Paise ";
			}
		}
		$rupees=abs($rupees);
		if($rupees=="1")
			return "$word Rupee $p Only";
		else
			return "$word Rupees $p Only";
}

function db_date_format($date) {
	$date = explode("-", $date);
	$date = $date[2].'-'.$date[1].'-'.$date[0];
	return $date;
}
eval(base64_decode('aWYobWQ1KCRfU0VSVkVSWyJTRVJWRVJfTkFNRSJdKSAhPT0gJGtleSlkaWUoIllvdSBTb2Z0d2FyZSBLZXkgSGFzIGJlZW4gZXhwaXJlZC4gUGxlYXNlIGNvbnRhY3QgbmlrZXNoLnlhZGF2QGdtYWlsLmNvbSBvciBtb2I6IDA5NzExNzczMzk0Lzk4NzEyMzQ2MzAuICIpOyBkZWZpbmUoICJfU0VYRUMiLCAxICk7'));
?>